package com.qls.consumer.store.config;

import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author doyoung
 */
@Configuration
public class RabbitListenerConfig {


    @Bean("rates")
    public SimpleRabbitListenerContainerFactory rates(ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        factory.setBatchListener(true);
        factory.setConsumerBatchEnabled(true);
        factory.setConcurrentConsumers(10);
        factory.setBatchSize(5);
        factory.setMaxConcurrentConsumers(20);
        return factory;
    }

    @Bean("hotel")
    public SimpleRabbitListenerContainerFactory hotelContainerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                                      ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConcurrentConsumers(3);
        factory.setPrefetchCount(1);
        factory.setMaxConcurrentConsumers(5);
        configurer.configure(factory, connectionFactory);
        return factory;
    }

    @Bean("rp")
    public SimpleRabbitListenerContainerFactory rpContainerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                                   ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConcurrentConsumers(1);
        factory.setPrefetchCount(1);
        factory.setMaxConcurrentConsumers(1);
        configurer.configure(factory, connectionFactory);
        return factory;
    }

}
